package vsy.buzzwordbingo.client;

import javax.swing.JFrame;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.springframework.http.client.CommonsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;




public class GameClient {
	public static String path = "localhost";
	/**
	 * starts the game client
	 */
	public static void main(String[] args) {
		TitleWindow title = new TitleWindow();
		JFrame fenster = title.getTitleWindow();
		fenster.setVisible(true);

	}

	public static RestTemplate userAuthenticate() {
		HttpClient client = new HttpClient();
		UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(TitleWindow.playerData.getUsername(),TitleWindow.playerData.getPW());
		client.getState().setCredentials(new AuthScope(path, 8080, AuthScope.ANY_REALM), credentials);
		CommonsClientHttpRequestFactory commons = new CommonsClientHttpRequestFactory(client);
		
		return new RestTemplate(commons);
	}

	public static void logout() {
		String name = TitleWindow.playerData.getUsername();
		GameClient.userAuthenticate().delete("http://"+path+":8080/buzzwordbingo/rest/players/" + name);
	}
}
